package com.hs.live.common.entity.response;

import com.hs.live.common.enums.ResponseCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description: 统一返回实体
 * @Author 胡尚
 * @Date: 2024/9/6 16:51
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseCommon<T> {

    private Integer code;
    private String msg;
    private String errorCode;
    private T data;


    public static <T> ResponseCommon<T> success() {
        return new ResponseCommon<>(ResponseCodeEnum.success.getCode(), null, null, null);
    }

    public static <T> ResponseCommon<T> success(T data) {
        return new ResponseCommon<>(ResponseCodeEnum.success.getCode(), null, null, data);
    }

    public static <T> ResponseCommon<T> error() {
        return new ResponseCommon<>(ResponseCodeEnum.error.getCode(), ResponseCodeEnum.error.getDescribe(), null, null);
    }

    public static <T> ResponseCommon<T> error(String msg) {
        return new ResponseCommon<>(ResponseCodeEnum.error.getCode(), msg, null, null);
    }

    public static <T> ResponseCommon<T> error(String msg, String errorCode) {
        return new ResponseCommon<>(ResponseCodeEnum.error.getCode(), msg, errorCode, null);
    }
}
